<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <textarea name="" id="demo" cols="30" rows="10"></textarea>
</body>
<script>
    // onkeydown  键盘按下时触发
    // onkeyup    按键松开时触发
    // onkeypress 绑定给表单元素  input  textarea  在表单元素中按下才能触发

    // document.onkeydown = function (e) {
    //     console.log(e.key + "按下");
    // }
    document.onkeyup = function (e) {
        console.log(e.key + "松开");
    }
    
    var demo = document.getElementById("demo");
    demo.onkeypress = function(e){
        console.log(e.key + "按下");
    }

    // onmouseenter 代替  onmouseover
    // onmouseleave 代替  onmouseout
</script>

</html>